package com.spiro.common;

import java.util.concurrent.atomic.AtomicInteger;

import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.server.ServerContext;
import org.apache.thrift.server.TServerEventHandler;
import org.apache.thrift.transport.TTransport;


public class MyServerEventHandler implements TServerEventHandler{

    private AtomicInteger clientCount = new AtomicInteger();
    
    @Override
    public void preServe() {
        System.out.println("thread_name=" + Thread.currentThread().getName() + ", preServe");
    }

    @Override
    public ServerContext createContext(TProtocol input, TProtocol output) {
        
        System.out.println("thread_name=" + Thread.currentThread().getName() + ", add one connection, now client.count=" + clientCount.incrementAndGet());
        return null;
    }

    @Override
    public void deleteContext(ServerContext serverContext, TProtocol input,
            TProtocol output) {
        System.out.println("thread_name=" + Thread.currentThread().getName() + ", delete one connection, now client.count=" + clientCount.decrementAndGet());
    }

    @Override
    public void processContext(ServerContext serverContext,
            TTransport inputTransport, TTransport outputTransport) {
        
        // TODO Auto-bintest method stub
//        System.out.println("thread_name=" + Thread.currentThread().getName() + ", processContext");
    }

}
